axios.defaults.baseURL ='http://api-breakingnews-web.itheima.net'


// 添加请求拦截器
axios.interceptors.request.use(function (config){
    if(config.url.indexOf('/my')!==- -1){
        config.headers.Authorization = localStorage.getItem('token')
    }
    // 修改完毕的config需要返回
    return config
},function (error){
    return Promise.reject(error)
})

// 添加响应拦截器
axios.interceptors.response.use(function (response){
    if(response.data.message ==='身份认证失败！') {
        location.href ='/login.html'
        localStorage.removeItem('token')
        return
    }
    return response;
},function (error){
    return Promise.reject(error)
})